package com.maolong.fenkufenbiaotest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maolong.fenkufenbiaotest.mapper.ProdDetailMapper;
import com.maolong.fenkufenbiaotest.pojo.ProdDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProdDetailService {

    @Autowired
    private ProdDetailMapper prodDetailMapper;

    public void addProdDetail(ProdDetail prodDetail) {
        // 插入数据时，Sharding-JDBC 会自动根据 addTime 来选择表
        prodDetailMapper.insert(prodDetail);
    }

    public List<ProdDetail> getProdDetailsByMonth(Date month) {
        QueryWrapper<ProdDetail> queryWrapper = new QueryWrapper<>();

        return prodDetailMapper.selectList(queryWrapper);
    }

    public List<ProdDetail> selectByPage() {
        Page<ProdDetail> page = new Page<>(1, 10);  // 第1页，每页10条数据
        System.out.println(page.getCurrent());
        System.out.println(page.getSize());
        IPage<ProdDetail> prodDetailIPage = prodDetailMapper.selectByPage(page);
        System.out.println(prodDetailIPage.getTotal());
        return prodDetailIPage.getRecords();
    }
}